package com.cw.jeeyt.service.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import com.cw.jeeyt.service.cache.InitCacheInfo;

/**
 * 初始化平台基础信息
 *
 * @author chenw
 */
@Component
public class PortalContextLoadListener implements ApplicationListener<ApplicationStartedEvent> {

    private static final Logger logger = LoggerFactory.getLogger(PortalContextLoadListener.class);

    @Autowired
    private InitCacheInfo initCacheInfo;

    /**
     * JEEYT平台基础数据初始化
     *
     * @param event
     * @see
     */
    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        logger.info("---初始化JEEYT平台基础数据【开始】---");
        // 2.执行同步数据库表和配置文件的内容
        try {
            initCacheInfo.putAllCacheInfo();
        } catch (Exception e) {
            logger.error("Error when sync Portlets", e);
        }
        logger.info("---初始化JEEYT平台基础数据【结束】---");
    }

}
